package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.PChatListVo;
import com.ruoyi.system.domain.bo.PChatListBo;
import com.ruoyi.system.service.IPChatListService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 聊天列Controller
 *
 * @author ruoyi
 * @date 2022-08-22
 */
@Validated
@Api(value = "聊天列控制器", tags = {"聊天列管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/chatList")
public class PChatListController extends BaseController {

    private final IPChatListService iPChatListService;

    /**
     * 查询聊天列列表
     */
    @ApiOperation("查询聊天列列表")
    @SaCheckPermission("system:chatList:list")
    @GetMapping("/list")
    public TableDataInfo<PChatListVo> list(PChatListBo bo, PageQuery pageQuery) {
        return iPChatListService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出聊天列列表
     */
    @ApiOperation("导出聊天列列表")
    @SaCheckPermission("system:chatList:export")
    @Log(title = "聊天列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PChatListBo bo, HttpServletResponse response) {
        List<PChatListVo> list = iPChatListService.queryList(bo);
        ExcelUtil.exportExcel(list, "聊天列", PChatListVo.class, response);
    }

    /**
     * 获取聊天列详细信息
     */
    @ApiOperation("获取聊天列详细信息")
    @SaCheckPermission("system:chatList:query")
    @GetMapping("/{id}")
    public R<PChatListVo> getInfo(@ApiParam("主键")
                                     @NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(iPChatListService.queryById(id));
    }

    /**
     * 新增聊天列
     */
    @ApiOperation("新增聊天列")
    @SaCheckPermission("system:chatList:add")
    @Log(title = "聊天列", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PChatListBo bo) {
        return toAjax(iPChatListService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改聊天列
     */
    @ApiOperation("修改聊天列")
    @SaCheckPermission("system:chatList:edit")
    @Log(title = "聊天列", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PChatListBo bo) {
        return toAjax(iPChatListService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除聊天列
     */
    @ApiOperation("删除聊天列")
    @SaCheckPermission("system:chatList:remove")
    @Log(title = "聊天列", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iPChatListService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
